<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use Cart;
use DB;

class ShopController extends Controller
{
    /**
     * 显示商品页
     * @return \Illuminate\Http\Response
     */
    public function Index()
    {
        $res = DB::table('goods') -> select()-> get();
        return view('denglu.good',['data'=>$res]);
    }


    /**
     * 执行添加
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function Add($id)
    {
       $data = DB::table('goods') -> where('id','=',$id) -> select() -> first();

        $arr['id'] = $data -> id;
        $arr['name'] = $data -> title;
        $arr['price'] = $data -> price;
        
        $arr['qty'] = 1;
        
        Cart::add($arr);

        return redirect('/shop/show');          
    }


    /**
     * 显示购物车
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */

    public function Show()
    {
        $res = Cart::content();
        return view('denglu.shop',['data' => $res]);
    }

    /**
     * 移除数据
     *
     * @return \Illuminate\Http\Response
     */
    public function Move($rowId)
    {
        Cart::remove($rowId);
        $res = Cart::content();
        return view('denglu.shop',['data' => $res]);        
    }


    /**
     * 清空购物车
     *
     * @return \Illuminate\Http\Response
     */
    public function Destroy()
    {
        Cart::destroy();
        $res = Cart::content();
        return view('denglu.shop',['data' => $res]);        
    }

   
}
